//
//  LockUsersVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/13.
//  Copyright © 2020 tym. All rights reserved.
//

#import "LockUsersVC.h"
#import "FamilyUserVC.h"
#import "UIView+ZJFrame.h"
#import "Sizes.h"
#import "UIimage+Extends.h"
#import "NotBoundUserVC.h"
#import "ZJScrollPageView.h"
@interface LockUsersVC ()

@property(nonatomic,strong) ZJScrollPageView *scrollPageView;

@property(nonatomic,strong) FamilyUserVC *familyVC;
@property(nonatomic,strong) NotBoundUserVC *notBoundVC;
@end

@implementation LockUsersVC

-(instancetype)initWithEquipment:(EquipmentModel*)equiment{
    
    self = [super init];
    self.equipmentModel = equiment;
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"用户管理"];
    
    [self initScrollView];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

}

-(void)initScrollView{
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    style.titleFont = Font_Regular(16);
    style.selectedTitleFont = Font_Medium(16);
    style.showLine = YES;
    style.scrollLineHeight = 3;
    style.coverCornerRadius = 15;
    style.coverHeight = 30;
    style.scrollLineColor = [rgbaa(0,0,0,0) colorWithAlphaComponent:0];
    style.segmentHeight = 44;
    style.segmentViewBounces = NO;
    style.normalTitleColor = rgba(74, 74, 74);
    style.selectedTitleColor = rgba(74, 74, 74);
    style.contentViewBounces = NO;
    style.adjustCoverOrLineWidth = YES;
    style.autoAdjustTitlesWidth = YES;
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight - NavigateonHeight - SafeBottomMargin) segmentStyle:style titles:@[@"门锁用户",
    @"未绑定"] parentViewController:self delegate:self];
    
    [scrollPageView bringSubviewToFront:scrollPageView.segmentView];
    scrollPageView.contentView.frame = CGRectMake(0,style.segmentHeight, ScreenWidth, scrollPageView.zj_height-style.segmentHeight);

    UIView *colorLine = [[UIView alloc] initWithFrame:CGRectZero];
    colorLine.backgroundColor = rgba(53, 54, 70);
    [scrollPageView.segmentView.scrollLine addSubview:colorLine];
    [colorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(scrollPageView.segmentView.scrollLine);
        make.size.mas_equalTo(CGSizeMake(14, 3.5));
    }];
    scrollPageView.segmentView.backgroundColor = [UIColor whiteColor];
    scrollPageView.contentView.backgroundColor = [UIColor whiteColor];
    scrollPageView.contentView.collectionView.backgroundColor = [UIColor whiteColor];
    scrollPageView.backgroundColor = [UIColor whiteColor];
    [scrollPageView setSelectedIndex:0 animated:NO];
    self.scrollPageView = scrollPageView;
    [self.view addSubview:self.scrollPageView];
}


-(FamilyUserVC*)familyVC{
    if (_familyVC == nil) {
        _familyVC = [[FamilyUserVC alloc] initWithEquipment:_equipmentModel];
    }
    return _familyVC;
}

-(NotBoundUserVC*)notBoundVC{
    if (_notBoundVC == nil) {
        _notBoundVC = [[NotBoundUserVC alloc] initEquipmentModel:self.equipmentModel];
    }
    return _notBoundVC;
}

//ZJScrollViewDelegate
- (NSInteger)numberOfChildViewControllers{
    return 2;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    if (index == 0) {
        return self.familyVC;
    }else{
        return self.notBoundVC;
    }
    return nil;
}

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
    return NO;
}

@end
